<?php

echo "冒泡排序：";

$arr = [9,2,7,10,25,21,86,19,42];
$len = count($arr);

for ($i=0; $i < $len; $i++) 
{ 
	$flag = false;
	for ($j=0; $j < $len-$i-1; $j++) 
	{ 
		if($arr[$j]>$arr[$j+1])
		{
			$tmp = $arr[$j];
			$arr[$j] = $arr[$j+1];
			$arr[$j+1] = $tmp;
			$flag = $tmp;
		}
	}
	if(!$flag)
	{
		break;
	}
}
print_r($arr);

echo "<hr/>";
echo "插入排序：";

$array = [9,2,6,10,25,21,86,1,42];
$lent = count($array);

for ($i=0; $i < $len-1; $i++) 
{ 
	$min = $i;
	for ($j=$i+1; $j < $len; $j++) 
	{ 
		if($array[$min]>$array[$j])
		{
			$min = $j;
		}
	}
	if($i!=$min)
	{
		$tmp = $array[$i];
		$array[$i] = $array[$min];
		$array[$min] = $tmp;
	}
}
print_r($array);

echo "<hr/>";
echo "选择排序：";

for ($i=1; $i < $len; $i++) 
{ 
	$val = $arr[$i];
	$j = $i-1;
	for (; $j >=0 ; $j--) 
	{ 
		if ($arr[$j]>$val) 
		{
			$arr[$j+1] = $val;
		}else{
			break;
		}
	}
	$arr[$j+1] = $val;
}
print_r($arr);
?>